Add bounding box tag to GPX output.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 17 Jan 2004 17:38:27 +0000 (17:38 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 17 Jan 2004 17:38:27 +0000 (17:38 +0000)
Accumulate xsi_schema_loc tags.

gpsbabel/defs.h
gpsbabel/gpx.c

index cb08cbbc5461a20eae668d851a351326c540428a..35992a32e79a334036e7e9ba750d77d049765d3d 100644 (file)
@@ -181,6 +181,16 @@ typedef struct {
        int rte_waypt_ct;               /* # waypoints in waypoint list */
 } route_head;
 
+/*
+ *  Bounding box information.
+ */
+typedef struct {
+       double max_lat;
+       double max_lon;
+       double min_lat;
+       double min_lon;
+} bounds;
+
 typedef void (*ff_init) (char const *);
 typedef void (*ff_deinit) (void);
 typedef void (*ff_read) (void);
@@ -207,6 +217,7 @@ waypoint * waypt_new(void);
 void waypt_del (waypoint *);
 void waypt_free (waypoint *);
 void waypt_disp_all(waypt_cb);
+void waypt_compute_bounds(bounds *);
 void waypt_flush(queue *);
 void waypt_flush_all(void);
 unsigned int waypt_count(void);
index 74e1aebaada8e7a51aab79c70e82e086d680ee34..cc4d573fa23c5f6264448e9e884b3b83c7f118e6 100644 (file)
@@ -32,6 +32,7 @@ static int logpoint_ct = 0;
 
 static const char *gpx_version;
 static const char *gpx_creator;
+static char *xsi_schema_loc;
 
 static char *gpx_email = NULL;
 static char *gpx_author = NULL;
@@ -56,6 +57,8 @@ static route_head *rte_head;
 
 #define MYNAME "GPX"
 #define MY_CBUF 4096
+#define DEFAULT_XSI_SCHEMA_LOC "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"
+
 typedef enum {
        tt_unknown = 0,
        tt_gpx,
@@ -212,6 +215,12 @@ tag_gpx(const char **attrv)
                else if (strcmp(avp[0], "src") == 0) {
                        gpx_creator = avp[1];
                }
+               else if (strcmp(avp[0], "xsi:schemaLocation") == 0) {
+                       if (0 == strstr(xsi_schema_loc, avp[1])) {
+                           xsi_schema_loc = xstrappend(xsi_schema_loc, " ");
+                           xsi_schema_loc = xstrappend(xsi_schema_loc, avp[1]);
+                       }
+               }
                avp+=2;
        }
 }
@@ -715,6 +724,8 @@ gpx_rd_init(const char *fname)
        cdatastr = vmem_alloc(1, 0);
        *((char *)cdatastr.mem) = '\0';
 
+       xsi_schema_loc = xstrdup(DEFAULT_XSI_SCHEMA_LOC);
+
        XML_SetElementHandler(psr, gpx_start, gpx_end);
        XML_SetCharacterDataHandler(psr, gpx_cdata);
 }
@@ -1101,6 +1112,7 @@ gpx_write(void)
 {
        time_t now = 0;
        int short_length;
+       bounds bounds;
        
         time( &now );
 
@@ -1120,10 +1132,14 @@ gpx_write(void)
        fprintf(ofd, "creator=\"GPSBabel - http://gpsbabel.sourceforge.net\"\n");
        fprintf(ofd, "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
        fprintf(ofd, "xmlns=\"http://www.topografix.com/GPX/1/0\"\n");
-       fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n");
+       fprintf(ofd, "xsi:schemaLocation=\"%s\">\n", xsi_schema_loc ? xsi_schema_loc : DEFAULT_XSI_SCHEMA_LOC);
 
         gpx_write_time( now, "time" );
-
+       waypt_compute_bounds(&bounds);
+       fprintf(ofd, "<bounds minlat=\"%f\" minlon =\"%f\" "
+                      "maxlat=\"%f\" maxlon=\"%f\" />\n",
+                      bounds.min_lat, bounds.min_lon, 
+                      bounds.max_lat, bounds.max_lon);
        waypt_disp_all(gpx_waypt_pr);
        gpx_track_pr();
        gpx_route_pr();